package com.bw.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.config.Result;
import com.bw.domain.SysPost;
import com.bw.service.SysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王钰--WY
 * @create 2023-08-20 19:27
 */
@RestController
@RequestMapping("/post")
public class PostController {
    @Autowired
    SysPostService sysPostService;
    @RequestMapping("/list")
    public Result<Page> list(Page page,@RequestBody SysPost sysPost){
        LambdaQueryWrapper<SysPost> wrapper = new LambdaQueryWrapper<SysPost>()
                .like(ObjectUtil.isNotEmpty(sysPost.getPostCode()), SysPost::getPostCode, sysPost.getPostCode())
                .like(ObjectUtil.isNotEmpty(sysPost.getPostName()), SysPost::getPostName, sysPost.getPostName())
                .eq(ObjectUtil.isNotEmpty(sysPost.getStatus()), SysPost::getStatus, sysPost.getStatus())
                .orderByAsc(SysPost::getPostSort);
        Page pageList = sysPostService.page(page, wrapper);
        return Result.ok(pageList);
    }
}
